import Vuex from 'vuex';
import Vue from 'vue';

Vue.use(Vuex);

// 需要返回一个 返回Vuex.store的实例的函数

let token = window.localStorage.getItem('token');

const store = () => new Vuex.Store({
  state:{
    itemList:[],
    itemNameSearch:null,
    condition:{},
    authenticated:token,

  },
  getters:{
    getList(state) {
      return state.itemList;
    },
    getItemNameSearch(state){
      return state.itemNameSearch;
    },
    getCondition(state){
      return state.condition;
    },
    getAuthenticated(state){
      return state.authenticated;
    }
  },
  mutations:{
    setAuthenticated(state,payload) {
      state.authenticated = payload;
    },
    setList(state,payload) {
      state.itemList = payload;
    },
    setItemNameSearch(state,payload){
      state.itemNameSearch = payload;
    },
    setCondition(state,payload){
      state.condition = payload;
    }
  },
  actions:{
    getList(store,payload){
      store.commit('setList',payload.num)
    },
    setCondition(store,payload){
      store.commit('setCondition',payload)
    }
  }
});


export default store;
